/********************************************************************************
 * Project Name		[JavaEE_Web]
 * File Name     	[FileUploadListener.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package file.upload.commons;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * 该监听器负责初始化配置信息
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
@WebListener
public class FileUploadListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent event) {
		ServletContext context = event.getServletContext();
		InputStream inputStream = context
				.getResourceAsStream("/WEB-INF/classes/file/upload/commons/uploadConfig.properties");
		Properties properties = new Properties();
		try {
			properties.load(inputStream);
			context.setAttribute("fileConfig", properties);
			System.out.println("properties = " + properties.size());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void contextDestroyed(ServletContextEvent event) {
	}
}
